package com.taobao.android.mnndemo;

import android.util.Log;

public class FPSCounter {
    private static final String TAG = "c";
    private long lastTime = 0;
    private int frames = 0;
    private float fps = 0.0f;

    public FPSCounter() {
        lastTime = System.nanoTime();
    }

    public void logFrame() {
        frames++;
        long currentTime = System.nanoTime();
        long delta = currentTime - lastTime;

        if (delta >= 1000000000) { // 1 second in nanoseconds
            fps = frames * 1000000000.0f / delta;
            frames = 0;
            lastTime = currentTime;
            Log.d(TAG, "logFrame:FPS: " + fps);
//            System.out.println("FPS: " + fps);
        }
    }

    public float getFPS() {
        return fps;
    }
}